﻿<UserControl x:Class="EpiNEXT.WPF.View.Pages.Search"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls="clr-namespace:EpiNEXT.WPF;assembly=EpiNEXT.WPF"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="600">
    <UserControl.InputBindings>
        <KeyBinding Key="Escape" Command="{Binding ToggleSearchCommand}" />
    </UserControl.InputBindings>
    <Grid>
        
        <Grid.Background>
            <SolidColorBrush Color="Black" Opacity="0.2" />
        </Grid.Background>

        <Border Margin="30" Background="{StaticResource LightPanelBackgroundBrush}" BorderBrush="{StaticResource HighlightBrush}" BorderThickness="1">
        <Grid Margin="30" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <StackPanel Margin="0, 20, 0, 0" Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button
                                    Content="Close"
                                    Command="{Binding HideSearchCommand}"
                                    Width="90" Margin="0, 0, 0, 0">
                    </Button>
                </StackPanel>

            <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch">
                    <Rectangle HorizontalAlignment="Left" Width="100" Height="6" Fill="{StaticResource AccentBrush}" />
                    <TextBlock VerticalAlignment="Center" Foreground="{StaticResource VeryLightTextBrush}" Style="{StaticResource Heading1}">SEARCH</TextBlock>
            </StackPanel>

            <StackPanel Grid.Row="1" Grid.Column="1">
                    <!--<StackPanel.InputBindings>
                        <KeyBinding Key="Enter" Command="{Binding SearchRecords}" />
                    </StackPanel.InputBindings>-->
                    <StackPanel Height="4" />
                    <controls:SearchBox SearchText="{Binding SelectedForm.SearchString, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
                                Search="{Binding SelectedForm.SearchRecords}" />
                    <StackPanel Height="4" />
            </StackPanel>

            <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
                <DataGrid x:Name="dgRecords" VerticalAlignment="Stretch"
                      Visibility="{Binding IsShowingSearch, Converter={StaticResource BooleanToVisibilityConverter}}"
                          ItemsSource="{Binding SelectedForm.RecordsView, Mode=Default, IsAsync=True, FallbackValue=...}"
                          IsSynchronizedWithCurrentItem="False"
                            VirtualizingStackPanel.IsVirtualizing="True"
                            VirtualizingStackPanel.VirtualizationMode="Recycling"
                      IsReadOnly="True"
                      IsVisibleChanged="dgRecords_IsVisibleChanged"
                          AutoGenerateColumns="False">
                    <DataGrid.Columns>
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </Grid>
        </Border>
    </Grid>
</UserControl>
